import { createApp, h } from 'vue'
import {
  Tabbar,
  TabbarItem,
  ActionBar,
  ActionBarIcon,
  ActionBarButton,
  Divider,
  Popup,
  Overlay,
  Loading,
  Dialog,
  ContactCard,
  Form,
  AddressEdit,
  AddressList,
  Field,
  CellGroup,
  Cell,
  SwipeCell,
  Icon,
  Stepper,
  Card,
  Checkbox,
  CheckboxGroup,
  Button,
  Swipe,
  SwipeItem,
  PullRefresh,
  List,
  Tab,
  Tabs,
  SubmitBar,
  Toast,
  Skeleton,
  NavBar,
  Search,
  ShareSheet,
  Tag,
  Grid,
  GridItem,
  Image as VanImage,
  Sticky,
  Badge,
  Col,
  Row,
  ActionSheet,
  IndexBar,
  IndexAnchor
} from 'vant'
import App from './App'
import router from './router'
import store from './store'

import videoSmall from './components/video-box/video-small'
import videoMedium from './components/video-box/video-medium.vue'
import SvgIcon from '@/components/svg-icon'
import 'lib-flexible/flexible'
import 'vant/lib/index.css'
import directive from './directive'

const app = createApp({
  render: () => h(App),
  created() {
    console.log('App created')
  },
  mounted() {
    store.dispatch('theme/GET')
  },
  watch: {
    '$route': {
      handler(to) {
        store.commit('wrapper/SET_PAGE', to)
      }
    }
  }
})
// 注册指令
directive(app)
app.component('video-small', videoSmall)
app.component('video-medium', videoMedium)

// 导入svg组件
const req = require.context('@/assets/svg-icons', false, /\.svg$/)
req.keys().map(req)
app.component('svg-icon', SvgIcon)

// 修改Toast全局配置
Toast.setDefaultOptions({ duration: 3000 })

// vant
app
  .use(Tabbar)
  .use(TabbarItem)
  .use(ActionBarButton)
  .use(ActionBarIcon)
  .use(ActionBar)
  .use(Divider)
  .use(Popup)
  .use(Overlay)
  .use(Loading)
  .use(Dialog)
  .use(Toast)
  .use(ContactCard)
  .use(Form)
  .use(AddressEdit)
  .use(AddressList)
  .use(Field)
  .use(CellGroup)
  .use(Cell)
  .use(SwipeCell)
  .use(Icon)
  .use(Stepper)
  .use(Card)
  .use(Button)
  .use(Swipe)
  .use(SwipeItem)
  .use(PullRefresh)
  .use(List)
  .use(Tab)
  .use(Tabs)
  .use(SubmitBar)
  .use(Checkbox)
  .use(CheckboxGroup)
  .use(Skeleton)
  .use(NavBar)
  .use(Search)
  .use(ShareSheet)
  .use(Tag)
  .use(Grid)
  .use(GridItem)
  .use(VanImage)
  .use(Sticky)
  .use(Badge)
  .use(Col)
  .use(Row)
  .use(ActionSheet)
  .use(IndexBar)
  .use(IndexAnchor);
app.use(router).use(store).mount('#app')